using UnityEngine;
using UnityEngine.Events;

public class MyGUISlider : GUIControl
{
    public float minVale = 0;
    public float maxVale = 1;
    [Range(0,1)]
    public float nowVale = 0;
    public E_Slider_Type sliderType = E_Slider_Type.Horizontal;

    public GUIStyle styleThumb;

    private float oldVale = 0;
    public event UnityAction<float> ChangeValue;
    protected override void StyleOffDraw()
    {
        switch (sliderType)
        {
            case E_Slider_Type.Horizontal:
                nowVale = GUI.HorizontalSlider(guiPos.Pos, nowVale, minVale, maxVale);
                break;
            case E_Slider_Type.Vertical:
                nowVale = GUI.VerticalSlider(guiPos.Pos, nowVale, minVale, maxVale);
                break;
        }
        if (oldVale != nowVale)
        {
            ChangeValue?.Invoke(nowVale);
            oldVale = nowVale;
        }
    }

    protected override void StyleOnDraw()
    {
        switch (sliderType)
        {
            case E_Slider_Type.Horizontal:
                nowVale = GUI.HorizontalSlider(guiPos.Pos, nowVale, minVale, maxVale, style, styleThumb);
                break;
            case E_Slider_Type.Vertical:
                nowVale = GUI.VerticalSlider(guiPos.Pos, nowVale, minVale, maxVale, style, styleThumb);
                break;
        }
        if (oldVale != nowVale)
        {
            ChangeValue?.Invoke(nowVale);
            oldVale = nowVale;
        }
    }

}
